package com.kingdee.eas.hr.emp.client;

import java.awt.event.ItemEvent;
import java.util.Date;

import com.kingdee.bos.ctrl.swing.event.DataChangeEvent;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.eas.custom.hostelmgr.basedata.DistributionOrNotEnum;
import com.kingdee.eas.custom.hostelmgr.basedata.HostelBasicFactory;
import com.kingdee.eas.custom.hostelmgr.basedata.HostelBasicInfo;
import com.kingdee.eas.custom.hostelmgr.basedata.NeedRoomEnum;
import com.kingdee.eas.hr.rec.util.DateUtil;

public class EmployeeBaseInfoUIPIEx extends EmployeeBaseInfoUI {

	private static final long serialVersionUID = -1311037812980096693L;

	public EmployeeBaseInfoUIPIEx() throws Exception {
		super();
	}

	@Override
	public void loadFields() {
		if (this.editData.getFullNamePingYin() != null) {
			this.editData.setFullNamePingYin(this.editData.getFullNamePingYin()
					.toUpperCase());
		}

		super.loadFields();
	}

	public void onLoad() throws Exception {
		super.onLoad();
		Date birthday = this.editData.getBirthday();
		int age = DateUtil.getYear(new Date()) - DateUtil.getYear(birthday);
		this.txtage.setValue(age);
		this.txtjoinStatus.setEnabled(false);
		this.contpersonDiff.setVisible(false);
		this.isDistribution.setEnabled(false);
	}

	@Override
	protected void prmtbed_dataChanged(DataChangeEvent e) throws Exception {
		HostelBasicInfo bed = (HostelBasicInfo) e.getNewValue();

		SelectorItemCollection selectors = new SelectorItemCollection();
		selectors.add("*");
		selectors.add("parent.*");
		selectors.add("parent.parent.*");
		selectors.add("parent.parent.parent.*");
		selectors.add("parent.parent.parent.parent.*");
		bed = HostelBasicFactory.getRemoteInstance().getHostelBasicInfo(
				new ObjectUuidPK(bed.getId()), selectors);

		this.prmtbuilding.setValue(bed.getParent().getParent().getParent()
				.getParent());
		this.prmtunit.setValue(bed.getParent().getParent().getParent());
		this.prmtfloor.setValue(bed.getParent().getParent());
		this.prmtroom.setValue(bed.getParent());

	}

	@Override
	protected void isRoom_itemStateChanged(ItemEvent e) throws Exception {
		super.isRoom_itemStateChanged(e);
		if (this.isRoom.getSelectedItem() == null) {
			return;
		}
		NeedRoomEnum needRoomEnum = (NeedRoomEnum) this.isRoom
				.getSelectedItem();
		if (needRoomEnum.equals(needRoomEnum.NO)) {
			this.isDistribution.setSelectedItem(DistributionOrNotEnum.NO);
		}
	}
}